import QtQuick 2.15
import QtQuick.Controls 2.5
import "./FlipClock" as FCL
import "./CircularClock" as CCL
import UIModule 1.0

Item {

    id:root

    property int pageCount: 2   // 总页数
    property int buffer: 1      // 保持前后多少页的加载，其他页卸载
    property point ballorigin
    property int moveX :0
    property int nowX: 0

    signal clicked()



    SwipeView {
        id: swipeView
        anchors.fill: parent
        currentIndex: 0


        Repeater {
            model: root.pageCount
            delegate: Item {
                width: swipeView.width
                height: swipeView.height

                Loader {
                    id: pageLoader
                    anchors.fill: parent
                    active: Math.abs(index - swipeView.currentIndex) <= buffer
                    sourceComponent: pageComponent(index)
                }
            }
        }
    }

    // 根据 index 返回不同的页面组件
    function pageComponent(idx) {
        switch(idx) {
        case 0:
            return flipClockComponent
        case 1:
            return circularClockComponent
        default:
            return defaultPageComponent
        }
    }

    Component {
        id: flipClockComponent
        FCL.FlipClock{
            id:flipItem
            width: root.width
            height: root.height
            hideSecondEn: UI.hideSecondEn
            h24:UI.timeFormat === UI.H24
            //visible: false
        }
    }

    Component {
        id: circularClockComponent
        CCL.CircularClock{
            id:circularItem
            width: root.width
            h24:UI.timeFormat === UI.H24
            hideSecondEn: UI.hideSecondEn
            height: root.height
        }
    }

    Component {
        id: defaultPageComponent
        Rectangle {
            color: "lightgray"
            anchors.fill: parent
            Text { text: "Other Page"; anchors.centerIn: parent; font.pixelSize: 24 }
        }
    }


}
